import { http } from "@/utils/http";

/** 文件信息模型定义 */
export type FileInfoModel = {
  name: string;         // 名称
  path: string;         // 完整路径
  isDir: boolean;       // 是否目录
  size: number;         // 大小(字节)
  modTime: string;      // 修改时间
  creationTime: string; // 创建时间
};

/** 分页响应模型 */
export type Resp<T> = {
  code: number;
  message: string;
  data: T;
};

/** 获取根目录列表 */
export const getDirListApi = (serverKey: string) => {
  return http.request<Resp<{
    list: FileInfoModel[]
  }>>("get", "/clusters/distribute-files/dir-list", {
    params: { serverKey }
  });
};

/** 获取子目录列表 */
export const getSubDirListApi = (serverKey: string, path: string) => {
  return http.request<Resp<{
    list: FileInfoModel[]
  }>>("get", "/clusters/distribute-files/sub-dir-list", {
    params: { serverKey, path }
  });
};

/** 删除目录 */
export const deleteDirApi = (serverKey: string, path: string) => {
  return http.request<Resp<{
    success: boolean
  }>>("delete", "/clusters/distribute-files/dir", {
    data: { serverKey, path }
  });
};